//页面中的数据
var data = [
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三1",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "图文问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三2",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "删除",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三3",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "电话问诊",
    cost: "20",
    orderStatus: "待支付",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三4",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "问诊记录",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三5",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "图文问诊",
    cost: "20",
    orderStatus: "待支付",
    operation: "查看订单",
    record: "问诊记录",
    del: "删除",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三6",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "电话问诊",
    cost: "20",
    orderStatus: "待支付",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-03-07 21:00:00",
    name: "张三7",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "问诊记录",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三8",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "待支付",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三9",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "待支付",
    operation: "查看订单",
    record: "问诊记录",
    del: "删除",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三10",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "问诊记录",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三11",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-05-07 21:00:00",
    name: "张三12",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "电话问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三13",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三14",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三15",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三16",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "图文问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三17",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三18",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "电话问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三19",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三20",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "进行中",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三21",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-08-07 21:00:00",
    name: "张三22",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三23",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三24",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三25",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "电话问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三26",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三27",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三28",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三29",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三30",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已完成",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三31",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三32",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三33",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "电话问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三34",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三35",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三36",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三37",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三38",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三39",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "电话问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三40",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已取消",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三41",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三42",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三43",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三44",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三45",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三46",
    department: "内科",
    doctor: "田田",
    way: "视频问诊",
    source: "电话问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三47",
    department: "内科",
    doctor: "田田",
    way: "视频咨询",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三48",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "电话问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三49",
    department: "内科",
    doctor: "田田",
    way: "图文咨询",
    source: "视频问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
  {
    checked: false,
    time: "2020-02-07 21:00:00",
    name: "张三50",
    department: "内科",
    doctor: "田田",
    way: "电话咨询",
    source: "图文问诊",
    cost: "20",
    orderStatus: "已退诊",
    operation: "查看订单",
    record: "",
    del: "",
  },
];
var oTit = document.querySelector(".Interrogation-choose");
var oLi = document.querySelectorAll("#dropdown0 ul li");

for (var i = 0; i < oLi.length; i++) {
  oLi[i].onclick = function () {
    oTit.innerText = this.innerText;
  };
}

var oTit2 = document.querySelector(".Interrogation-choose1");
var oLi1 = document.querySelectorAll("#dropdown1 ul li");

for (var i = 0; i < oLi1.length; i++) {
  oLi1[i].onclick = function () {
    oTit2.innerText = this.innerText;
  };
}

var oTit3 = document.querySelector(".Interrogation-choose2");
var oLi2 = document.querySelectorAll("#dropdown2 ul li");

for (var i = 0; i < oLi2.length; i++) {
  oLi2[i].onclick = function () {
    oTit3.innerText = this.innerText;
  };
}

var returnBtn = document.querySelector(".return-btn");
var oShow = document.querySelector(".show-box");
var lineItem = document.querySelector(".line-item");
var recordImg = document.querySelector(".record-img");
var recordNone = document.querySelector(".record-none");
//待支付
var oUnpaid = document.querySelector("#allOptions");
//当前的页码
var page = 1;
//每页的条数
var count = 10;
//共计多少条数据
var totalOf = document.querySelector(".total-of");
//获取tbody
var oTBody = document.querySelector("tbody");
//批量删除
var oBatchDel = document.querySelector(".batchDel");
//获取分页容器
var oPagination = document.querySelector(".pagination");
//获取上一页的按钮
var oPrevBtn = document.querySelector(".prev");
//获取下一页的按钮
var oNextBtn = document.querySelector(".next");
//页面初始化的渲染功能var a=0;
//获取搜索的输入框
var oSearchInp = document.querySelector(".searchInp");
//获取筛选按钮
var oSearchBtn = document.querySelector(".searchBtn");
//获取重置按钮
var oResetBtn = document.querySelector(".resetBtn");
//开始和结束时间框
var inputDate = document.querySelector("#inputdate");
var inputDate1 = document.querySelector("#inputdate1");
//获取批量删除
var batchDel = document.querySelector(".batchDel");
var allInput;

//重置事件
oResetBtn.addEventListener("click", resetFn);
function resetFn() {
  oSearchInp.value = "";
  oTit.innerText = "请选择...";
  oTit2.innerText = "请选择...";
  oTit3.innerText = "请选择...";
  inputDate.value = "";
  inputDate1.value = "";
  render();
}

//筛选事件
oSearchBtn.addEventListener("click", searchFn);
function searchFn() {
  page = 1;
  render();
}

//条件
var conditions = "全部";

//渲染函数
function render() {
  //代表开始和结束时间
  var startTime =
    inputDate.value == ""
      ? new Date("1992-1-1").getTime()
      : new Date(inputDate.value).getTime();
  var endTime =
    inputDate1.value == ""
      ? new Date().getTime()
      : new Date(inputDate1.value).getTime();
  //代表搜索框的值
  var search = oSearchInp.value; // oSearchInp.value
  var titStr = oTit.innerText;
  var titStr2 = oTit2.innerText;
  var titStr3 = oTit3.innerText;
  var renderData = [];
  if (search.trim() == "") {
    renderData = data;
  } else {
    for (var i = 0; i < data.length; i++) {
      //如果每条数据中的名字里面包含搜索的内容
      //模糊搜索
      if (data[i].name.includes(search)) {
        //|| data[i].orderStatus.includes(titStr)
        //就把符合条件的内容放进渲染的数据中
        renderData.push(data[i]);
      }
    }
  }

  var renderData2 = [];
  if (titStr == "请选择...") {
    renderData2 = renderData;
  } else {
    for (var i = 0; i < renderData.length; i++) {
      //如果每条数据中的名字里面包含搜索的内容
      //模糊搜索
      if (renderData[i].orderStatus == titStr) {
        //就把符合条件的内容放进渲染的数据中
        renderData2.push(renderData[i]);
      }
    }
  }
  // console.log(renderData2);

  var renderData3 = [];
  if (titStr2 == "请选择...") {
    renderData3 = renderData2;
  } else {
    for (var i = 0; i < renderData2.length; i++) {
      //如果每条数据中的名字里面包含搜索的内容
      //模糊搜索
      if (renderData2[i].way == titStr2) {
        //就把符合条件的内容放进渲染的数据中
        renderData3.push(renderData2[i]);
      }
    }
  }
  // console.log(renderData3);

  var renderData4 = [];
  if (titStr3 == "请选择...") {
    renderData4 = renderData3;
  } else {
    for (var i = 0; i < renderData3.length; i++) {
      //如果每条数据中的名字里面包含搜索的内容
      //模糊搜索
      if (renderData3[i].source == titStr3) {
        //就把符合条件的内容放进渲染的数据中
        renderData4.push(renderData3[i]);
      }
    }
  }
  // console.log(renderData4);

  var renderData5 = [];
  for (var i = 0; i < renderData4.length; i++) {
    if (
      new Date(renderData4[i].time).getTime() >= startTime &&
      new Date(renderData4[i].time).getTime() <= endTime
    ) {
      renderData5.push(renderData4[i]);
    }
  }

  // console.log(renderData5);

  var renderData6 = [];
  if (conditions == "全部") {
    renderData6 = renderData5;
  } else {
    for (var i = 0; i < renderData5.length; i++) {
      // console.log(renderData5[i].orderStatus, conditions);
      if (renderData5[i].orderStatus == conditions) {
        renderData6.push(renderData2[i]);
      }
    }
  }
  // console.log(renderData6);

  //让table为空
  oTBody.innerHTML = "";
  //根据count和page准备要渲染的数据
  var renderArr = renderData6.slice((page - 1) * count, page * count);
  //循环要渲染的数据
  for (var i = 0; i < renderArr.length; i++) {
    //创建tr
    var oTr = document.createElement("tr");
    //给tr创建内容
    oTr.innerHTML = `
        <td><input type="checkbox" class="tdInput" ></td>
        <td>${renderArr[i].time}</td>
        <td>${renderArr[i].name}</td>
        <td>${renderArr[i].department}</td>
        <td>${renderArr[i].doctor}</td>
        <td>${renderArr[i].way}</td>
        <td>${renderArr[i].source}</td>
        <td>${renderArr[i].cost}</td>
        <td>${renderArr[i].orderStatus}</td>
        <td id="td1"><span class="operation">${renderArr[i].operation}</span><span class="record">${renderArr[i].record}</span><span class="del">${renderArr[i].del}</span></td>
        
    `;
    //把tr创建到tbody里面
    oTBody.appendChild(oTr);
    //共计多少条数据
    totalOf.innerHTML =
      "共" +
      Math.ceil(renderData6.length / count) +
      "页/" +
      renderData6.length +
      "条数据";
  }

  //渲染页码
  //找到所有的1，2，3，4的页码
  var aPageBtn = document.querySelectorAll(".pageBtn");
  //删除所有的页码
  for (var i = 0; i < aPageBtn.length; i++) {
    oPagination.removeChild(aPageBtn[i].parentNode);
  }
  //根据数据的长度重新创建页码
  for (var i = 1; i <= Math.ceil(renderData6.length / count); i++) {
    //创建li
    var oLi = document.createElement("li");
    //给li创建内容
    oLi.innerHTML = `<a class="pageBtn">${i}</a>`;
    //如果li和当前的页码一致，给他加一个选中的class
    if (i == page) {
      oLi.classList.add("active");
    }
    //在下一页的前面插入页码
    oPagination.insertBefore(oLi, oPagination.lastElementChild);
  }

  //全选
  var allInputSpan = document.querySelector(".allInputSpan");
  allInput = document.querySelector("#allInput");
  var aInput = oTBody.querySelectorAll("input");
  // console.log(aInput);
  allInputSpan.onclick = function () {
    if (allInput.checked == false) {
      allInput.checked = true;
      for (var i = 0; i < aInput.length; i++) {
        aInput[i].checked = true;
      }
    } else {
      allInput.checked = false;
      for (var i = 0; i < aInput.length; i++) {
        aInput[i].checked = false;
      }
    }
  };
}
//一上来就渲染一次数据。全部数据
render();

// 批量删除功能
/*
    当点击了批量删除    
    将勾选了的 tr全部删除  遍历  将勾选了的input的tr另存在一个数组里
    并删除数据
 */
// 获取批量删除

var deleteArr = []; //存删除的tr
var checkId = []; //存被删除的 tr 的id
oBatchDel.addEventListener("click", oBatchDelFn);
function oBatchDelFn() {
  aCheckSmall = document.querySelectorAll("tbody >tr>td>input");
  console.log(aCheckSmall);
  for (var i = 0; i < aCheckSmall.length; i++) {
    if (aCheckSmall[i].checked == true) {
      deleteArr.push(aCheckSmall[i]);
    }
  }
  for (var j = 0; j < deleteArr.length; j++) {
    // 找到每一项的id  存在数组里
    checkId.push(deleteArr[j].parentNode.parentNode.children[2].innerText);
  }
  console.log(checkId);
  // 根据名字id删除对应的数据 然后进行数据渲染
  for (var i = 0; i < checkId.length; i++) {
    for (var j = 0; j < data.length; j++) {
      if (checkId[i] == data[j].name) {
        //删除id所对应的数据
        data.splice(j, 1);
        allInput.checked = false;
      }
    }
  }
  console.log(data);
  //重新渲染
  render();
  /* 
       清空 deleteArr = []; //存删除的tr
        checkId = []; //存被删除的 tr 的id 
   */

  deleteArr = [];
  checkId = [];
}

//给分页加事件
oPagination.addEventListener("click", changePage);
function changePage() {
  //如果当前点击的按钮有pageBtn这个class名字
  if (event.target.className == "pageBtn") {
    //修改全局的page
    page = event.target.innerText;
    allInput.checked = false;
    //渲染table，渲染分页
    render();
  }
}
//给上一页和下一页加事件
oPrevBtn.addEventListener("click", prev);
oNextBtn.addEventListener("click", next);
function prev() {
  if (page > 1) {
    page--;
    allInput.checked = false;
    render();
  }
}
function next() {
  if (page < Math.ceil(data.length / count)) {
    page++;
    allInput.checked = false;
    render();
  }
}
//隐藏查看订单
returnBtn.onclick = function () {
  oShow.style.display = "block";
  lineItem.style.display = "none";
};

// 删除和查看问诊单功能
oTBody.addEventListener("click", del);
function del() {
  if (event.target.className.includes("del")) {
    // console.log(event.target.className);
    //找到id
    var name = event.target.parentNode.parentNode.children[2].innerText;
    // console.log(event.target.parentNode.parentNode.children[2].innerText);
    //循环数据对比
    for (var i = 0; i < data.length; i++) {
      if (data[i].name == name) {
        //删除id所对应的数据
        data.splice(i, 1);
      }
      //共计多少条数据
      totalOf.innerHTML =
        "共" + Math.ceil(data.length / count) + "页/" + data.length + "条数据";
    }

    //重新渲染
    render();
  }
  //查看问诊单
  else if (event.target.className.includes("record")) {
    // console.log(event.target.className.includes("record"));
    recordImg.style.display = "block";
  }
  //查看订单
  else if (event.target.className.includes("operation")) {
    oShow.style.display = "none";
    orderName.innerHTML =
      event.target.parentNode.previousElementSibling.innerHTML;
    stateName.innerHTML =
      event.target.parentNode.previousElementSibling.innerHTML;
    // console.log(screeningAccepts.innerHTML)
    if (orderName.innerHTML == "已完成") {
      screeningAccepts.style.display = "block";
    } else {
      screeningAccepts.style.display = "none";
    }
    lineItem.style.display = "block";
  }
}
recordNone.addEventListener("click", recordNoneFn);
function recordNoneFn() {
  recordImg.style.display = "none";
}

var screeningAccepts = document.querySelector(".screening-accepts");
var stateName = document.querySelector(".stateName");
var orderName = document.querySelector(".orderName");

var uDiv = oUnpaid.querySelectorAll("div");
function oUnpaidFn() {
  for (var j = 0; j < uDiv.length; j++) {
    uDiv[j].classList.remove("active");
  }
  event.target.classList.add("active");
  conditions = event.target.innerText;
  page = 1;
  render();
}
oUnpaid.addEventListener("click", oUnpaidFn);

// console.log(oTBody.children[0].cells[0].children)

/* 
        每页是5条  count
        data  
    1   0-5
    2   5-10
    3   10-15
    n   (n-1)*count   n*count
-----------------------------
        data  每页是5条  count 
    
    1    1
    5    1
    6    2
    10   2
    11   3
    n    Math.ceil(n/count)


 */
